class Solution {
    public:
        int findLongestChain(vector<vector<int>>& pairs) {
            sort(pairs.begin(),pairs.end(),[](const vector<int>& left,const vector<int>& right)->bool{ return left[0] < right[0];});
            int n = pairs.size();
            vector<int> dp(n,1);
            int ret = 1;
            for(int i =1 ; i < n ; i++){
                for(int j = i-1; j >= 0 ;j--){
                    if(pairs[i][0]>pairs[j][1]){
                        dp[i] = dp[j] +1;
                        break;
                    }
                }
                ret = max(ret,dp[i]);
            }
            return ret;
        }
    };